package com.simon.jkxj.ui.diagnostic

import android.os.Bundle
import android.view.View
import androidx.appcompat.app.AppCompatActivity
import androidx.recyclerview.widget.LinearLayoutManager
import androidx.recyclerview.widget.RecyclerView
import com.simon.jkxj.R
import com.simon.jkxj.databinding.ActivityRespiratoryDiagnosisResultBinding

class RespiratoryDiagnosisResultActivity : AppCompatActivity() {
    private lateinit var binding: ActivityRespiratoryDiagnosisResultBinding

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        binding = ActivityRespiratoryDiagnosisResultBinding.inflate(layoutInflater)
        setContentView(binding.root)

        setupToolbar()
        displayDiagnosisResult()
    }

    private fun setupToolbar() {
        binding.toolbar.setNavigationOnClickListener {
            onBackPressed()
        }
    }

    private fun displayDiagnosisResult() {
        // 获取传递的诊断结果
        val diseaseType = intent.getStringExtra("diseaseType") ?: "未确定"
        val symptoms = intent.getStringArrayListExtra("symptoms") ?: arrayListOf()
        val severity = intent.getStringExtra("severity") ?: "待评估"
        val treatmentPlan = intent.getStringExtra("treatmentPlan") ?: "暂无治疗方案"
        val lifestyleAdvice = intent.getStringArrayListExtra("lifestyleAdvice") ?: arrayListOf()
        val dietaryAdvice = intent.getStringArrayListExtra("dietaryAdvice") ?: arrayListOf()
        val exerciseAdvice = intent.getStringArrayListExtra("exerciseAdvice") ?: arrayListOf()
        val medicationAdvice = intent.getStringArrayListExtra("medicationAdvice") ?: arrayListOf()

        // 显示疾病类型和严重程度
        binding.tvDiseaseType.text = diseaseType
        binding.tvSeverity.text = when (severity) {
            "轻度" -> "轻度症状"
            "中度" -> "中度症状"
            "重度" -> "重度症状"
            else -> "待评估"
        }

        // 显示症状列表
        binding.tvSymptoms.text = if (symptoms.isEmpty()) "暂无症状记录" else symptoms.joinToString("、")

        // 显示治疗方案
        binding.tvTreatmentPlan.text = treatmentPlan

        // 设置建议列表
        setupAdviceList(binding.rvLifestyleAdvice, lifestyleAdvice)
        setupAdviceList(binding.rvDietaryAdvice, dietaryAdvice)
        setupAdviceList(binding.rvExerciseAdvice, exerciseAdvice)
        setupAdviceList(binding.rvMedicationAdvice, medicationAdvice)
    }

    private fun setupAdviceList(recyclerView: RecyclerView, adviceList: ArrayList<String>) {
        recyclerView.layoutManager = LinearLayoutManager(this)
        recyclerView.adapter = AdviceAdapter(adviceList)
    }
} 